/*******************************************************************************
 * Copyright (c) 2008, 2009 Fabio Mauro - Alberto Terraneo.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 1.2
 * or any later version published by the Free Software Foundation.
 *     
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Free Documentation License for more details.
 *     
 * You should have received a copy of the GNU Free Documentation 
 * License along with this distribution; if not, send a email to authors:
 * aterraneo <at> users.sourceforge.net
 * bigmoby09 <at> users.sourceforge.net
 *******************************************************************************/
package it.blueocean.acanto.web.pages.secure.famiglia;

import it.blueocean.acanto.dao.FamigliaDao;
import it.blueocean.acanto.model.Famiglia;
import it.blueocean.acanto.model.Prodotto;
import it.blueocean.acanto.web.platform.components.panel.AcantoPanel;
import it.blueocean.acanto.web.platform.components.repeaters.AcantoDefaultDataTable;
import it.blueocean.acanto.web.platform.providers.AcantoProvider;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ListaFamiglie extends AcantoPanel
{
	private static final long serialVersionUID = 2022239405641534350L;

	private static final Logger log = LoggerFactory.getLogger(ListaFamiglie.class);

	@SpringBean
	private FamigliaDao famigliaDao;
	
	@SuppressWarnings("unchecked")
	public ListaFamiglie(String id)
	{
		super(id);
		add(new Label("name", "Lista famiglie"));

		final AcantoProvider<Famiglia> dataProvider = new AcantoProvider<Famiglia>(getListaFamiglie(), "cdg");

		List<IColumn<?>> columns = new ArrayList<IColumn<?>>();
		            
		columns.add(new PropertyColumn(new Model<String>("Prima Colonna"), "cdg", "cdg"));
		columns.add(new PropertyColumn(new Model<String>("Seconda Colonna"), "note", "note"));

		AcantoDefaultDataTable dataTable = new AcantoDefaultDataTable("datatable", columns, dataProvider);

		add(dataTable);
	}
	
	private List<Famiglia> getListaFamiglie()
	{
		List<String> eagerAttributes = new ArrayList<String>();
		eagerAttributes.add("gruppo");
		
		List<Famiglia> listFamiglie = (List<Famiglia>)famigliaDao.findAll(eagerAttributes.toArray(new String[eagerAttributes.size()]));
		
		return listFamiglie;
	}

}
